package cn.edu.xaut.mybatisers.mall.ServiceImp;

import cn.edu.xaut.mybatisers.mall.Dao.FavouriteDao;
import cn.edu.xaut.mybatisers.mall.Entity.Favourite;
import cn.edu.xaut.mybatisers.mall.Service.FavouriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.sql.SQLException;
import java.util.List;

@Service
@SuppressWarnings("all")
public class FavouriteServiceImp implements FavouriteService {
    @Autowired
    FavouriteDao favouriteDao;
    @Override
    public Boolean incF(Favourite f) throws SQLException {
        if (!favouriteDao.getAllFavourite(f.getConsumer_id()).contains(f.getCommodity_id()))
            favouriteDao.incF(f);
        return true;
    }

    @Override
    public Boolean subF(Favourite f) throws SQLException {
        favouriteDao.subF(f);
        return true;
    }

    @Override
    public List<Integer> getAllFavourite(HttpSession session) throws SQLException {
        return favouriteDao.getAllFavourite((Integer) session.getAttribute("consumer_id"));
    }
}
